package com.jelly.web.modules.basics.websiteDetails.controller;

import com.jelly.common.constant.GlobalConstant;
import com.jelly.common.note.OperationLog;
import com.jelly.common.util.web.AjaxPostResponse;
import com.jelly.web.modules.basics.websiteDetails.domain.WebUpload;
import com.jelly.web.share.base.controller.BaseController;
import com.jelly.web.modules.basics.websiteDetails.domain.WebEssential;
import com.jelly.web.modules.basics.websiteDetails.domain.WebMail;
import com.jelly.web.modules.basics.websiteDetails.domain.WebsiteDetails;
import com.jelly.web.modules.basics.websiteDetails.service.IWebsiteDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @创建人 ql
 * @创建时间 2018-10-11 15:01
 * @项目名称 jelly
 * @功能描述: 网站信息控制器
 **/
@Controller
@RequestMapping("/admin/basics/website")
public class WebsiteDetailsController extends BaseController {

    @Autowired
    private IWebsiteDetailsService websiteDetailsService;

    /**
     * 获取网站信息
     * @return
     */
    @GetMapping
    public String getWebsiteDetailsList(Model model){

        //获取字典详情
        getDictionary();

        //获取该用户可访问的按钮详情
        getButton();

        model.addAttribute("websiteDetails",websiteDetailsService.getWebsiteDetailsAll());

        return adminBasicsWebsiteDetails("/list");

    }

    /**
     * 修改网站信息
     * @param websiteDetails
     * @param webEssential
     * @param webMail
     * @return
     */
    @PostMapping("/update")
    @OperationLog(name = "网站信息模块",value = GlobalConstant.UPDATE)
    @ResponseBody
    public ResponseEntity<AjaxPostResponse> updateBulletin(WebsiteDetails websiteDetails ,WebEssential webEssential, WebMail webMail,WebUpload webUpload){
        websiteDetails.setWebEssential(webEssential);
        websiteDetails.setWebMail(webMail);
        websiteDetails.setWebUpload(webUpload);
        return websiteDetailsService.updateWebsiteDetails(websiteDetails)?okResponse("修改成功"):errorResponse("修改失败");
    }

}
